#include "SDL/SDL.h"
#include "SDL/SDL_OpenGL.h"
#include <time.h>

#include "Combat/CombatHandler.h"

int main(int argc, char** argv) {
	int width = 800;
	int height = 600;
	bool fullscreen = false;

	SDL_Init(SDL_INIT_VIDEO);

	SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
	if(SDL_SetVideoMode(width, height, 32, SDL_OPENGL | (fullscreen ? SDL_FULLSCREEN : 0)) == NULL) return 1;

	SDL_ShowCursor(false);
	SDL_WM_SetCaption("The Game", NULL);

	glViewport(0, 0, width, height);

	glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST);

	glDepthFunc(GL_ALWAYS);
	glEnable(GL_DEPTH_TEST);

	glClearDepth(0);

	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	glAlphaFunc(GL_GREATER, 0);

	glEnable(GL_TEXTURE_2D);
	glEnable(GL_BLEND);
	glEnable(GL_ALPHA_TEST);

	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	glOrtho(0, width, height, 0, 0, 255);
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();

	Font font;
	font.init("fonts/lsans.ttf");
	Font::activeFont = &font;

	glColor3ub(255, 0, 0);
	glDisable(GL_LIGHTING);
	glDisable(GL_TEXTURE);
	glDisable(GL_TEXTURE_2D);

	CombatHandler ch;

	SDL_Event event;
	bool quit = false;
	while(!quit) {
		while(SDL_PollEvent(&event)) {
			if(event.type == SDL_QUIT) {
				quit = true;
			} else {
				ch.handleEvent(&event);
			}
		}

		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

		ch.draw();

		SDL_GL_SwapBuffers();
	}

	SDL_Quit();
	return 0;
}
